home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / samples / zscript / textset.zsc.z / textset.zsc
Encoding:
Text File  |  1997-01-22  |  1.1 KB  |  39 lines

  1. # Sample Z-Script function: textset
  2.  
  3. function textset () {
  4. #%
  5. #      textset varname unixcommand
  6. #
  7. # This function sets the variable indicated by varname to the output of
  8. # the given unixcommand.  For example:
  9. #
  10. #     textset files ls -a
  11. #     ask -i filename "Which file would you like?" $files
  12. #
  13. # Shortcomings:
  14. #
  15. # Quotation marks in the arguments of the unix command are handled badly,
  16. # because the command passes through both Z-Mail and the Unix shell.
  17. #
  18. # Single quotes in the output of unixcommand will produce errors.
  19. # Output of more than 1000 characters may produce errors.
  20. #
  21. # Multi-line output from the unix command is joined into a single line.
  22. #%
  23.     # There must be at least two arguments
  24.     if $# < 2
  25.     echo usage: $0 varname unixcommand
  26.     return -1
  27.     endif
  28.     # Extract the variable name
  29.     set _textset = $1
  30.     shift
  31.     # Use the shell to create a Z-Mail command that sets the variable
  32.     sh "TEXT=`$*`;echo set $_textset = \'"'$TEXT'"\' > /tmp/zc$$"
  33.     unset _textset
  34.     # Execute the Z-mail command just created
  35.     source /tmp/zc$$
  36.     # Remove the temporary file
  37.     sh rm /tmp/zc$$
  38. }
  39.